import timeFormat from "@/uview-ui/libs/function/timeFormat.js";
import store from "@/store";

export function marked(arr, str){
  let html = str;
  arr.map(item=>{
    if(!!item){
      let reg = new RegExp(item, "gi");
      html = html.replace(reg, `<b class="sjgjc" style="color: #FD5E3A">${item}</b>`);
    }
  });
  return html;
}

export function getFilterTime(type=0){
  let now = store.state.localDateTime;
	let date_time = [];
  switch(type){
  	case 0:
  	case 5:
  		date_time = [
  			timeFormat(now.getTime() - 7*24*60*60*1000, "yyyy-mm-dd hh:MM:ss"),
  			timeFormat(now.getTime(), "yyyy-mm-dd hh:MM:ss")
  		];
  		break;
  	case 1:
  		date_time = [
  			timeFormat(new Date().setHours(0, 0, 0, 0), "yyyy-mm-dd hh:MM:ss"),
  			timeFormat(now.getTime(), "yyyy-mm-dd hh:MM:ss")
  		];
  		break;
  	case 2:
  		let yesterday = new Date();
  		yesterday.setDate(new Date().getDate() - 1);
  		let startTime = yesterday.setHours(0, 0, 0, 0);
  		let endTime = yesterday.setHours(23, 59, 59, 999);
  		date_time = [
  			timeFormat(startTime, "yyyy-mm-dd hh:MM:ss"),
  			timeFormat(endTime, "yyyy-mm-dd hh:MM:ss")
  		];
  		break;
  	case 3:
  		date_time = [
  			timeFormat(now.getTime() - 1*24*60*60*1000, "yyyy-mm-dd hh:MM:ss"),
  			timeFormat(now.getTime(), "yyyy-mm-dd hh:MM:ss")
  		];
  		break;
  	case 4:
  		date_time = [
  			timeFormat(now.getTime() - 3*24*60*60*1000, "yyyy-mm-dd hh:MM:ss"),
  			timeFormat(now.getTime(), "yyyy-mm-dd hh:MM:ss")
  		];
  }
	return date_time;
}